package me.hushuang.webb.back.mapper;

import me.hushuang.webb.back.model.Resource;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 *
 */
public interface ResourceMapper {
    @Insert("insert into sys_resource(name,type) values(#{name}, #{type})")
    int createResource(final Resource resource);

    @Update("update sys_resource set name=#{name} where id=#{id}")
    Resource updateResource(Resource resource);

    @Delete("delete from sys_resource where id= #{id}")
    void deleteResource(Long resourceId);

    @Select("select id, name, type, url, permission, parent_id as parentId, parent_ids as parentIds, available from sys_resource where id=#{id}")
    Resource findOne(Long resourceId);

    @Select("select id, name, type, url, permission, parent_id as parentId, parent_ids as parentIds, available from sys_resource  order by concat(parent_ids, id) asc")
    List<Resource> findAll();

}
